{include file='admin/header.html'}

<div class="layui-container">
    <form class="layui-form">
        <div class="layui-form-item">
            <h2>找回密码
                <small style="float: right;">
                    <a href="{$site_url}/admin/login.html{if isset($smarty.request.redirect_to)}?redirect_to={$smarty.request.redirect_to|escape:html}{/if}"
                        title="切换登录">切换登录</a>
                </small>
            </h2>
        </div>
        <hr>
        <!-- 表单字段 -->
        <div class="layui-form-item">
            <div class="layui-form-label">邮箱地址</div>
            <div class="layui-input-block">
                <input type="email" name="email" value="" required lay-verify="required"
                    placeholder="您的注册邮箱" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-row">
                <div class="layui-col-xs7">
                    <label class="layui-form-label">验证码</label>
                    <div class="layui-input-inline captcha" style="width:75px;">
                        <input type="text" name="captcha" value="" required lay-verify="required" autocomplete="off"
                            placeholder="验证码" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-xs5">
                    <button type="button" class="layui-btn layui-btn-primary"
                        lay-on="verycode">获取验证码</button>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-form-label">新密码</div>
            <div class="layui-input-block">
                <input type="password" name="password" value="" required lay-verify="required" autocomplete="off"
                    placeholder="设置新密码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-form-label">确认密码</div>
            <div class="layui-input-block">
                <input type="password" name="repeat_password" value="" required lay-verify="required" autocomplete="off"
                    placeholder="确认新密码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                {if isset($smarty.request.redirect_to)}
                <input type="hidden" name="redirect_to" value="{$smarty.request.redirect_to|escape:html}">
                {/if}
                <input type="hidden" name="verify" value="reset">
                <button class="layui-btn" lay-submit lay-filter="forget">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<style>
    body {
        background: #01AAED;
    }

    body .layui-container {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        margin: auto;
        width: 380px;
        height: 420px;
        background: #fff;
        padding: 20px;
        border-radius: 4px;
        box-shadow: 5px 5px 20px #888;
        overflow: hidden;
    }
</style>
<script>
    // JS
    layui.use(['form', 'layer', 'util'], function () {
        var form = layui.form,
            layer = layui.layer,
            util = layui.util,
            $ = layui.jquery;

        // 监听提交
        form.on("submit(forget)", function (data) {
            $.post('{$site_url}/admin/forget.html', data.field, function (res) {
                if (res.code) {
                    return layer.alert(res.msg, { icon: 2 });
                }
                localStorage.removeItem('webToken');
                layer.alert(res.msg, { icon: 1 }, function (index) {
                    layer.close(index);
                    var _ta = window.location;
                    if (self.frameElement && self.frameElement.tagName == 'IFRAME') {
                        _ta = parent.window.location;
                    }
                    _ta.href = '{$site_url}/admin/login.html{if isset($smarty.request.redirect_to)}?redirect_to={$smarty.request.redirect_to|escape:html}{/if}';
                });
            }, "json");
            return false;
        });

        // 获取验证码
        util.event('lay-on', {
            verycode: function (othis) {
                var email = othis.parent().parent().parent().prev().find('input[name="email"]').val();
                // 倒计时函数
                var count = 60;
                othis.attr('disabled', true).addClass('layui-btn-disabled');
                var timer = setInterval(function () {
                    count--;
                    othis.text('重新发送 (' + count + ')');
                    if (count <= 0) {
                        clearInterval(timer);
                        othis.attr('disabled', false).removeClass('layui-btn-disabled').text('获取验证码');
                    }
                }, 1000);
                $.post('{$site_url}/admin/forget.html', { email: email, verify: 'send' }, function (res) {
                    if (res.code) {
                        clearInterval(timer);
                        othis.attr('disabled', false).removeClass('layui-btn-disabled').text('获取验证码');
                        return layer.alert(res.msg, { icon: 2 });
                    }
                    layer.msg(res.msg, { icon: 1, time: 3000 });
                }, 'json');
            }
        });
    });
</script>

{include file='admin/footer.html'}